
import {createPIXI} from "./libs/pixi.miniprogram.js"
import unsafeEval from "./libs/unsafeEval.js"
import installSpine from "./libs/pixi-spine.js"
import installAnimate from "./libs/pixi-animate.js"
// import pixi from './PIXI.js'
// let PIXI = {};

export default  (myCanvas = '#myCanvas', canvas2d = '#canvas2d', ctx,callback)=> {
  wx.createSelectorQuery().select(myCanvas).node().exec((res) => {
    const info = wx.getSystemInfoSync();
    const canvas = res[0].node;
    canvas.width = info.windowWidth;//设置canvas实际宽高
    canvas.height = info.windowHeight;//设置canvas实际宽高,从而实现全屏
    const stageWidth = info.windowWidth;
    const stageHeight = parseInt(stageWidth * info.windowHeight/info.windowWidth);//计算canvas实际高度
    wx.createSelectorQuery().select(canvas2d).node().exec((res2d) => {
      const canvas2d = res2d[0].node;
      canvas2d.width = 16;
      canvas2d.height = 16; 

      PIXI = createPIXI(canvas,stageWidth,canvas2d);//传入canvas，传入canvas宽度，用于计算触摸坐标比例适配触摸位置
      unsafeEval(PIXI);//适配PIXI里面使用的eval函数
      installSpine(PIXI);//注入Spine库
      installAnimate(PIXI);//注入Animate库
      //for import
      for(var p in PIXI){
        pixi[p] = PIXI[p]
      }

      callback(canvas, stageWidth, stageHeight)

    });
  });

};
